<div th:fragment="login">




    <!--    注册modal-->
    <style>
        .r_label {
            width: 80px;
            display: inline-block;
        }

        input.mszc {
            background: #0e82e8;
            color: #fff;
            border: none;
            padding: 10px 0;
            border-radius: 5px;
            width: 10%;
        }

        input.mszc1 {
            background: #0e82e8;
            color: #fff;
            border: none;
            padding: 2px 0;
            border-radius: 2px;
            width: 10%;
        }

        .page-zchy div {
            line-height: 35px;
        }
    </style>
    <div class="m-modal" id="loginModal">
        <div class="m-modal-dialog">
            <div class="m-top">
                <h4 class="m-modal-title">
                    登录
                </h4>
                <span class="m-modal-close">&times;</span>
            </div>
            <div class="m-middle">
                <!--                <iframe th:src="@{/cmsEnglish/register.html}"></iframe>-->
                <div class="page-zchy">
                    <form id="registerForm" method="post" >
<!--                        <h2 class="page-title">用户登录</h2>-->
                        <div>
                            <span class="r_label">手机号码：</span>
                            <span>
                                   <input name="accountNo" type="text" id="accountNo" maxlength="30" placeholder="手机号码">（必填）
                                </span>
                        </div>
                        <div>
                            <span class="r_label">密码：</span>
                            <span>
                                   <input name="pwd" type="password" id="pwd" maxlength="20" placeholder="密码">（必填）
                                </span>
                        </div>
                        <div>
                            <span class="r_label">验证码：</span>
                            <span style="display: inline-flex">
<!--                                <input name="checkCode" type="text" id="checkCode" maxlength="50" placeholder="验证码" style="">-->
<!--                                <img src="" id="imgCheckCode" style="width:110px;height:30px;padding:5px 3px">-->
<!--                                -->
                                                <input name="checkCode" type="text" id="checkCode" maxlength="50" placeholder="验证码" style="">
                <img src="" id="imgCheckCode" style="width:110px;height:30px;padding:0px 3px">
                                </span>
                        </div>
                        <div style="padding-top: 20px">
                            <input type="button" id="btnLogin" value="登录" class="mszc">
                        </div>

                    </form>
                </div>
            <!--                  <div class="m-bottom">-->
            <!--                      <button class="m-btn-sure">确定</button>-->
            <!--                      <button class="m-btn-cancel">取消</button>-->
            <!--                  </div>-->
        </div>
    </div>
    <!--          <button class="btn1">点击我，打开</button>-->
    <script type="text/javascript" th:src="@{/blog/js/jquery.my-modal.1.1.min.js}"></script>
        <script type="text/javascript" th:src="@{/blog/js/md5.js}"></script>
<!--    <script src="https://cdn.bootcdn.net/ajax/libs/blueimp-md5/2.16.0/js/md5.js"></script>-->
        <script>
            var loginModal = new MyModal.modal(function () {
                // alert("你点击了确定");
            },{'id':'loginModal'});
            // loginModal.id = "loginModal";
            // m1.show();
            $('.btn1').on("click", function () {

            });

            function openLogin() {
                loginModal.show();
            }


            function makeUuid() {
                var tick = parseInt(Date.now() / 1000),
                    max = 1e+9,
                    rand = parseInt((1+Math.random()) * max);
                return tick.toString(16) + rand.toString(16);
            }



            $(document).ready(function(){
                var deviceId = makeUuid();
                //图形验证码
                initImgCheckCode(deviceId);

                $("#btnLogin").click(function(){
                    var formParam = $("#registerForm").serializeArray()
                        .reduce(function (json, { name, value }) {
                            json[name] = value;
                            return json;
                        }, {});;

                    //校验
                    formParam['deviceId'] = deviceId;
                    // formParam['registerType'] = 2;
                    // formParam['pwd'] = md5(formParam['pwd']);
                    formParam['pwd'] = (CryptoJS.MD5(formParam['pwd']) + "").toUpperCase();
                    // var newParam = {accountNo:'1',pwd:1,email:'1'};

                    $.ajax({type:"POST",url:"/user/c/login",dataType:'JSON', contentType:'application/json', data:JSON.stringify(formParam),success:function(result){
                            if(result.success){
                                //设置cookie
                                // var token = result.data.token;
                                alert("登录成功");
                                window.location = "/cmsEnglish/index.html";
                            }else{
                                alert(result.message || '登录失败');
                            }

                        }});

                    // $.post("/user/c/register",JSON.stringify(formParam),function(result){
                    //     if(result.success){
                    //         //设置cookie
                    //         // var token = result.data.token;
                    //         alert("注册成功");
                    //         window.location = "/cmsEnglish/index.html";
                    //     }else{
                    //         alert(result.message || '注册失败');
                    //     }
                    // },"json");
                });
                $("#imgCheckCode").click(function(){
                    initImgCheckCode(deviceId);
                });


                function initImgCheckCode(deviceId){
                    let t = new Date().getTime();
                    $.get("/user/c/getImgCode?checkCodeType=1&deviceId="+deviceId+"&t="+t,function(res,status){
                        $("#imgCheckCode").prop("src",res.data);
                    });
                }
            });


        </script>
</div>

</div>
